﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BattleShipLibrary
{
    public class Ship
    {
        ShipType shipType;
        public enum ShipDirection { Vertical, Horizontal}
        ShipDirection shipDirection;

        public ShipDirection _ShipDirection
        {
            get { return shipDirection; }
            set { shipDirection = value; }
        }
       
        public ShipType ShipType
        {
            get { return shipType; }
            set { shipType = value; }
        }

        int shipSize = 0;

        public int ShipSize
        {
            get { return shipSize; }
           // set { shipSize = value; }
        }
        private char X1;

        public char _X1
        {
            get { return this.X1; }
            set { X1 = value; }
        }
        private char X2;

        public char _X2
        {
            get { return this.X2; }
            set { X2 = value; }
        }
        private int Y1;

        public int _Y1
        {
            get { return this.Y1; }
            set { Y1 = value; }
        }
        private int Y2;

        public int _Y2
        {
            get { return this.Y2; }
            set { Y2 = value; }
        }
        public Ship(char X1, int Y1, char X2, int Y2)
        {
            this.X1 = X1;
            this.X2 = X2;
            this.Y1 = Y1;
            this.Y2 = Y2;
            shipSize = Math.Abs(Y1 - Y2 + X1 - X2) + 1;
            switch (shipSize)
            {
                case 1:
                    shipType = ShipType.Corvete;
                    break;
                case 2:
                    shipType = ShipType.Fregate;
                    break;
                case 3:
                    shipType = ShipType.Destroyer;
                    break;
                case 4:
                    shipType = ShipType.AirCraftCarrie;
                    break;
                default:
                    break;
            }
           if(X1!=X2){
               shipDirection = ShipDirection.Horizontal;
           }
           else
           {
               shipDirection = ShipDirection.Vertical;
           }

            
        }

        public int XIndexToInt()
        {
            int xIndex=0;
            if (X1 < X2)
            {
                xIndex = X1 - 'A';
            }
            else
            {
                xIndex = X2 - 'A';
            }
            return xIndex;
        }
        public int[,] ShipLocattion()
        {
            int size = shipSize;
            int[,] shipLocation = new int [size,2];
            for (int i = 0; i < size; i++)
            {
                if (shipDirection == ShipDirection.Horizontal)
                {
                    shipLocation[i, 0] = XIndexToInt()+i;
                    shipLocation[i, 1] = Y1-1;
                }
                else
                {
                    shipLocation[i, 0] = XIndexToInt();
                    if (Y1 < Y2)
                    {
                        shipLocation[i, 1] = Y1 + i-1;
                    }
                    else
                    {
                        shipLocation[i, 1] = Y2 + i-1;
                    }
                    
                }
            }
                return shipLocation;
        }

    }
}
